Imports System.Data.SqlClient
Imports System.Data
Imports System.Windows.Forms

Partial Class frmModificarDatos
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim usr As String
        Dim cnx As SqlConnection
        Dim da1 As SqlDataAdapter
        Dim dt1 As DataTable
        Dim x1, x2 As String

        cnx = New SqlConnection(ConfigurationManager.AppSettings("strConexion"))
        cnx.Open()

        usr = CType(Session("usuario"), String)

        Try
            Dim sql As String = "select nombre,apellido from usuario where usuario = '" & usr & "' "
            Dim cmd As New SqlCommand(sql, cnx)
            da1 = New SqlDataAdapter(sql, cnx)
            dt1 = New DataTable
            da1.Fill(dt1)
            x1 = dt1.Rows(0)("nombre").ToString
            x2 = dt1.Rows(0)("apellido").ToString


            txtpa.Text = CType(Session("password"), String)

            txtNom.Text = x1
            txtApe.Text = x2

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        Link()

    End Sub

    Protected Sub btnAct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAct.Click
        Dim usr As String
        Dim cnx As SqlConnection
        Dim x1, x2, x3 As String

        cnx = New SqlConnection(ConfigurationManager.AppSettings("strConexion"))
        cnx.Open()

        usr = CType(Session("usuario"), String)
        x1 = txtPassN.Text
        x2 = txtNom.Text
        x3 = txtApe.Text

        Try

            Dim sql As String = "UPDATE Usuario SET pass= '" & x1 & "' , nombre = '" & x2 & "', apellido = '" & x3 & "' WHERE usuario = '" & usr & "'"
            Dim cmd As New SqlCommand(sql, cnx)
            cmd.ExecuteNonQuery()
            Response.Write("<script>alert('Datos Actualizados Satisfactoriamente');</script>")

        Catch ex As Exception

            ex.Message.ToString()

        End Try

        txtpa.Text = x1


    End Sub


    Public Sub Link()
        Dim tipo As String
        tipo = CType(Session("id_tipo"), String)
        Select Case tipo
            Case 1
                lnkVolver.NavigateUrl = "frmPaneldeControl.aspx"
            Case 2
                lnkVolver.NavigateUrl = "frmInicio.aspx"
            Case 3
                lnkVolver.NavigateUrl = "frmInicio2.aspx"
            Case 4
                lnkVolver.NavigateUrl = "frmInicio3.aspx"
            Case 5
                lnkVolver.NavigateUrl = "frmInicio4.aspx"
            Case Else
                lnkVolver.NavigateUrl = "frmLogin.aspx"
        End Select
    End Sub

End Class
